namespace ASPNET.StarterKit.IssueTracker
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class PickProject : UserControl
    {
        private ProjectCollection _DataSource;
        private bool _DisplayDefault;
        [AccessedThroughProperty("dropProjects")]
        private DropDownList _dropProjects;
        [AccessedThroughProperty("reqVal")]
        private RequiredFieldValidator _reqVal;
        private object designerPlaceholderDeclaration;

        public event EventHandler SelectedIndexChanged;

        public PickProject()
        {
            base.Init += new EventHandler(this.Page_Init);
            this._DisplayDefault = false;
        }

        public override void DataBind()
        {
            this.dropProjects.DataSource = this._DataSource;
            this.dropProjects.DataTextField = "Name";
            this.dropProjects.DataValueField = "Id";
            this.dropProjects.DataBind();
            if (this._DisplayDefault)
            {
                this.dropProjects.Items.Insert(0, new ListItem("-- Select Project --", "0"));
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        public void OnSelectedIndexChanged(EventArgs e)
        {
            if (this.SelectedIndexChanged != null)
            {
                this.SelectedIndexChanged(this, e);
            }
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        public void ProjectSelectedIndexChanged(object s, EventArgs e)
        {
            this.OnSelectedIndexChanged(e);
        }

        public void RemoveDefault()
        {
            ListItem defaultItem = this.dropProjects.Items.FindByValue("0");
            if (defaultItem != null)
            {
                this.dropProjects.Items.Remove(defaultItem);
            }
        }

        public bool AutoPostBack
        {
            get
            {
                return this.dropProjects.AutoPostBack;
            }
            set
            {
                this.dropProjects.AutoPostBack = value;
            }
        }

        public string CssClass
        {
            get
            {
                return this.dropProjects.CssClass;
            }
            set
            {
                this.dropProjects.CssClass = value;
            }
        }

        public ProjectCollection DataSource
        {
            get
            {
                return this._DataSource;
            }
            set
            {
                this._DataSource = value;
            }
        }

        public bool DisplayDefault
        {
            get
            {
                return this._DisplayDefault;
            }
            set
            {
                this._DisplayDefault = value;
            }
        }

        protected virtual DropDownList dropProjects
        {
            get
            {
                return this._dropProjects;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropProjects != null)
                {
                    this._dropProjects.SelectedIndexChanged -= new EventHandler(this.ProjectSelectedIndexChanged);
                }
                this._dropProjects = value;
                if (this._dropProjects != null)
                {
                    this._dropProjects.SelectedIndexChanged += new EventHandler(this.ProjectSelectedIndexChanged);
                }
            }
        }

        public bool Required
        {
            get
            {
                return this.reqVal.Visible;
            }
            set
            {
                this.reqVal.Visible = value;
            }
        }

        protected virtual RequiredFieldValidator reqVal
        {
            get
            {
                return this._reqVal;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._reqVal != null)
                {
                }
                this._reqVal = value;
                if (this._reqVal != null)
                {
                }
            }
        }

        public ListItem SelectedItem
        {
            get
            {
                return this.dropProjects.SelectedItem;
            }
        }

        public int SelectedValue
        {
            get
            {
                if (StringType.StrCmp(this.dropProjects.SelectedValue, string.Empty, false) == 0)
                {
                    return 0;
                }
                return int.Parse(this.dropProjects.SelectedValue);
            }
            set
            {
                this.dropProjects.SelectedValue = value.ToString();
            }
        }
    }
}

